package org.example.managere.repository.feibiao;

import org.example.managere.entity.feibiao.AmKnowledgeEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface AmKnowledgeEntityRepository extends JpaRepository<AmKnowledgeEntity, String> {
    
    /**
     * 根据实体名称查询
     */
    AmKnowledgeEntity findByEntityName(String entityName);
    
    /**
     * 根据实体名称模糊查询
     */
    List<AmKnowledgeEntity> findByEntityNameContaining(String entityName);
    
    /**
     * 根据实体类型查询
     */
    List<AmKnowledgeEntity> findByEntityType(String entityType);
    
    /**
     * 根据实体类型模糊查询
     */
    List<AmKnowledgeEntity> findByEntityTypeContaining(String entityType);
    
    /**
     * 根据录入时间范围查询
     */
    List<AmKnowledgeEntity> findByEntryTimeBetween(Date startDate, Date endDate);
    
    /**
     * 根据关键字在实体ID、实体名称或实体类型中进行模糊搜索
     */
    @Query("SELECT e FROM AmKnowledgeEntity e WHERE " +
           "e.entityId LIKE %:keyword% OR " +
           "e.entityName LIKE %:keyword% OR " +
           "e.entityType LIKE %:keyword%")
    Page<AmKnowledgeEntity> searchByKeyword(@Param("keyword") String keyword, Pageable pageable);
    
    /**
     * 统计某个类型的实体数量
     */
    long countByEntityType(String entityType);
} 